package com.jzr.open.controller.api;

import com.jzr.common.entity.vo.Result;
import com.jzr.common.util.U;
import com.jzr.open.db1.model.THospital;
import com.jzr.open.db1.service.HospitalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/hospital")
public class HospitalController {
    @Autowired
    private HospitalService hospitalService;

    @PostMapping("/get")
    public Result<THospital> get(){
        THospital hospital = hospitalService.getOne(null);
        return Result.success("成功",hospital,hospital==null ? 0 : 1);
    }

    @PostMapping("post")
    public Result<Boolean> post(@RequestBody THospital record){
        if(U.isBlank(record)){
            return Result.fail("数据不能为空");
        }
        if(U.isBlank(record.getName())){
            return Result.fail("参数name不能为空");
        }
        if(!hospitalService.save(record)){
            return Result.fail("保存失败");
        }else{
            return Result.success("保存成功",true);
        }
    }

}
